package presentation;

import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.event.KeyEvent;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;




import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import controle.ControlJButtonSaveEval;

import abstraction.Cours;
import abstraction.Evaluation;

/** classe qui crée la fenetre qui s'affiche lors de la création ou de la modification d'une évaluation
 * 
 * @author PICOSSON
 *
 */
public class EvalDialog extends JDialog {
	private static final long serialVersionUID = 1L;

	
	private JTextField nomEval;
	private JTextField dateEval;
	private JTextField modeEval;
	private int id_evaluation;
	private Cours modele;


	/** 
	 * 
	 * @param parent
	 * @param modele
	 * @param creation
	 */
	public EvalDialog (Frame parent, Cours modele, boolean creation){
		super(parent, "Evaluation", true);
		this.setMinimumSize(new Dimension(200, 350));
		this.modele = modele;


		JPanel form = new JPanel(new GridLayout(7, 1));
		form.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));

		form.add(new JLabel("Nom de l'evaluation"));
		nomEval = new JTextField();
		form.add(nomEval);
		form.add(new JLabel("Date de l'evaluation"));
		dateEval = new JTextField();
		dateEval.setToolTipText("La date au format yyyy-mm-dd");
		dateEval.setText("yyyy-mm-dd");
		form.add(dateEval);
		form.add(new JLabel("Mode de l'evaluation"));
		modeEval = new JTextField();
		form.add(modeEval);		
		
		JPanel buttons = new JPanel();
		JButton save = new JButton("OK");
		save.setMnemonic(KeyEvent.VK_ENTER);
		save.addActionListener(new ControlJButtonSaveEval(this, modele, creation));
		buttons.add(save);
		form.add(buttons);
		this.getRootPane().setDefaultButton(save);
		this.getContentPane().add(form);
		
		if (!creation) {
			System.out.println("Evaluation a modifier : " + (this.modele.getEvaluationCourante()));
			Evaluation courante = modele.findEvaluation(this.modele.getEvaluationCourante());
			nomEval.setText(courante.getNom());
			dateEval.setText(courante.getDate());
			modeEval.setText(courante.getMode_evaluation());
			this.id_evaluation = courante.getId_evaluation();
		}  
		else{
			this.id_evaluation = -1;
		}
		
		this.pack();
		this.setLocationRelativeTo(parent);
	}

	public int getId_evaluation() {
		return id_evaluation;
	}
	
	public void setId_evaluation(int id_evaluation) {
		this.id_evaluation = id_evaluation;
	}
	
	public String getNomEval() {
		return nomEval.getText();
	}

	public String getDateEval() throws ParseException {
		return this.dateEval.getText();		
	}

	public String getModeEval() {
		return modeEval.getText();
	}


}

